﻿namespace HRM.CORE.REPORT
{
    using DevExpress.Utils;
    using DevExpress.XtraEditors;
    using DevExpress.XtraPrinting;
    using DevExpress.XtraReports.UI;
    using Extra.ERP;
    using HRM.CORE;
    using System; using Extra.ERP;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Drawing.Printing;
    using System.Windows.Forms; using Common;

    public class rptContract : XtraReport
    {
        private BottomMarginBand BottomMargin;
        private IContainer components;
        private DetailBand Detail;
        private FormattingRule formattingRule1;
        private FormattingRule formattingRule2;
        private FormattingRule formattingRule3;
        private FormattingRule formattingRule4;
        private FormattingRule formattingRule5;
        private FormattingRule formattingRule6;
        private FormattingRule formattingRule7;
        private FormattingRule formattingRule8;
        private HRM_CONTRACT l_Contract;
        private string m_ContractCode;
        private string m_EmployeeCode;
        private string m_FilePath;
        private TopMarginBand TopMargin;
        private XRRichText xrRichText1;

        public rptContract()
        {
            this.components = null;
            this.l_Contract = new HRM_CONTRACT();
            this.m_EmployeeCode = "";
            this.m_ContractCode = "";
            this.m_FilePath = "";
            this.InitializeComponent();
        }

        public rptContract(string ContractCode, string EmployeeCode, string FilePath)
        {
            this.components = null;
            this.l_Contract = new HRM_CONTRACT();
            this.m_EmployeeCode = "";
            this.m_ContractCode = "";
            this.m_FilePath = "";
            this.InitializeComponent();
            this.m_ContractCode = ContractCode;
            this.m_EmployeeCode = EmployeeCode;
            this.m_FilePath = FilePath;
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void InitializeComponent()
        {
            ComponentResourceManager manager = new ComponentResourceManager(typeof(rptContract0));
            this.Detail = new DetailBand();
            this.xrRichText1 = new XRRichText();
            this.formattingRule1 = new FormattingRule();
            this.formattingRule2 = new FormattingRule();
            this.formattingRule3 = new FormattingRule();
            this.formattingRule4 = new FormattingRule();
            this.formattingRule5 = new FormattingRule();
            this.formattingRule7 = new FormattingRule();
            this.formattingRule8 = new FormattingRule();
            this.TopMargin = new TopMarginBand();
            this.BottomMargin = new BottomMarginBand();
            this.formattingRule6 = new FormattingRule();
            this.xrRichText1.BeginInit();
            this.BeginInit();
            this.Detail.Controls.AddRange(new XRControl[] { this.xrRichText1 });
            this.Detail.HeightF = 76f;
            this.Detail.Name = "Detail";
            this.Detail.Padding = new PaddingInfo(0, 0, 0, 0, 100f);
            this.Detail.TextAlignment = TextAlignment.TopLeft;
            this.xrRichText1.CanShrink = true;
            this.xrRichText1.FormattingRules.Add(this.formattingRule1);
            this.xrRichText1.FormattingRules.Add(this.formattingRule2);
            this.xrRichText1.FormattingRules.Add(this.formattingRule3);
            this.xrRichText1.FormattingRules.Add(this.formattingRule4);
            this.xrRichText1.FormattingRules.Add(this.formattingRule5);
            this.xrRichText1.FormattingRules.Add(this.formattingRule7);
            this.xrRichText1.FormattingRules.Add(this.formattingRule8);
            this.xrRichText1.LocationFloat = new PointFloat(0f, 0f);
            this.xrRichText1.Name = "xrRichText1";
            this.xrRichText1.Scripts.OnHtmlItemCreated = "xrRichText1_HtmlItemCreated";
            this.xrRichText1.SerializableRtfString = manager.GetString("xrRichText1.SerializableRtfString");
            this.xrRichText1.SizeF = new SizeF(684.9167f, 74.75001f);
            this.formattingRule1.Name = "formattingRule1";
            this.formattingRule2.Name = "formattingRule2";
            this.formattingRule3.Name = "formattingRule3";
            this.formattingRule4.Name = "formattingRule4";
            this.formattingRule5.Name = "formattingRule5";
            this.formattingRule7.Name = "formattingRule7";
            this.formattingRule8.Name = "formattingRule8";
            this.TopMargin.HeightF = 50f;
            this.TopMargin.Name = "TopMargin";
            this.TopMargin.Padding = new PaddingInfo(0, 0, 0, 0, 100f);
            this.TopMargin.TextAlignment = TextAlignment.TopLeft;
            this.BottomMargin.HeightF = 56f;
            this.BottomMargin.Name = "BottomMargin";
            this.BottomMargin.Padding = new PaddingInfo(0, 0, 0, 0, 100f);
            this.BottomMargin.TextAlignment = TextAlignment.TopLeft;
            this.formattingRule6.Name = "formattingRule6";
            base.Bands.AddRange(new Band[] { this.Detail, this.TopMargin, this.BottomMargin });
            base.Font = new Font("Times New Roman", 9.75f);
            base.FormattingRuleSheet.AddRange(new FormattingRule[] { this.formattingRule1, this.formattingRule2, this.formattingRule3, this.formattingRule4, this.formattingRule5, this.formattingRule6, this.formattingRule7, this.formattingRule8 });
            base.Margins = new Margins(90, 50, 50, 0x38);
            base.PageHeight = 0x491;
            base.PageWidth = 0x33b;
            base.PaperKind = PaperKind.A4;
            base.ScriptsSource = "\r\nprivate void xrRichText1_HtmlItemCreated(object sender, DevExpress.XtraReports.UI.HtmlEventArgs e) {\r\n\r\n}\r\n";
            base.Version = "9.3";
            this.BeforePrint += new PrintEventHandler(this.rptContract_BeforePrint);
            this.xrRichText1.EndInit();
            this.EndInit();
        }

        private void LoadAllData()
        {
            DataSet set = new DataSet();
            DataTable list = new DataTable();
            list = this.l_Contract.GetList(MyLogin.Level, MyLogin.Code);
            set.Tables.Add(list);
            base.DataSource = set;
            base.DataMember = list.TableName;
            base.DataAdapter = list;
        }

        private void LoadData()
        {
            DataSet set = new DataSet();
            DataTable listByContract = new DataTable();
            listByContract = this.l_Contract.GetListByContract(this.m_ContractCode, this.m_EmployeeCode);
            set.Tables.Add(listByContract);
            base.DataSource = set;
            base.DataMember = listByContract.TableName;
            base.DataAdapter = listByContract;
        }

        private void rptContract_BeforePrint(object sender, PrintEventArgs e)
        {
            ////if (MyInfo.Get(MyEncryption.Encrypt("ERP01", "123654", true)) == "OK")
            {
            }
            try
            {
                this.xrRichText1.LoadFile(this.m_FilePath);
            }
            catch
            {
                XtraMessageBox.Show("Kh\x00f4ng thể t\x00ecm thấy tập tin " + this.m_FilePath, "Th\x00f4ng B\x00e1o", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation);
                return;
            }
            if (this.m_EmployeeCode == "")
            {
                this.LoadAllData();
            }
            else
            {
                this.LoadData();
            }
        }
    }
}

